<template>
	<!-- 底部滑块列表 -->
	<view class="radio-list-container" v-if="filteredRadios.length">
		<scroll-view class="radio-list" scroll-x scroll-with-animation @scrolltolower="radioQueryStore.loadMore">
			<view class="radio-item" v-for="(radio, index) in filteredRadios" :key="'list-' + index"
				:class="{ active: currentRadio && currentRadio.stationuuid === radio.stationuuid }"
				@click="selectRadio(radio)">
				<SafeImage class="radio-cover" :src="radio.favicon" mode="aspectFill" />
				<text class="radio-name">{{ radio.name }}</text>
				<!-- <text class="radio-style">{{ }}</text> -->
			</view>
			<view v-if="radioQueryStore.isLoading" class="radio-item loading-indicator">
				<view class="loading-spinner"></view>
				<text class="radio-name">加载中...</text>
			</view>

		</scroll-view>
	</view>
</template>

<script lang="ts" setup>
import { ref, computed } from 'vue';
import { useStationStore } from '@/stores/useStationStore';
import type { Station } from '@/common/types/interface';
import { usePlayerStore } from '@/stores/usePlayerStore';
import { randomCoordinate } from '@/common/utils';
import { useRadioQueryStore } from '@/stores/useRadioQueryStore';
// const stationStore = useStationStore();
const radioQueryStore = useRadioQueryStore();

const playerStore = usePlayerStore();
const filteredRadios = computed(() => radioQueryStore.filteredList);
const currentRadio = ref<Station>();
const selectRadio = (radio: Station) => {
	currentRadio.value = radio;
	playerStore.switchStation(radio);
	if (!radio.geo_long) {
		uni.showToast({ title: '使用随机位置' });
		const coord = randomCoordinate();
		radio.geo_long = coord.longitude;
		radio.geo_lat = coord.latitude;
	}
}
</script>

<style>
/* 电台列表样式 */
.radio-list-container {
	width: 100%;
	height: 200rpx;
	background-color: #0f1c2e;
	padding: 20rpx;
	border-radius: 16px;
	box-shadow: 0 4rpx 16rpx rgba(0, 0, 0, 0.3);
}

.radio-list {
	white-space: nowrap;
	height: 100%;
}

.radio-item {
	display: inline-flex;
	flex-direction: column;
	width: 180rpx;
	height: 100%;
	margin-right: 24rpx;
	border-radius: 8px;
	overflow: hidden;
	background-color: rgba(255, 255, 255, 0.1);
	transition: all 0.3s ease;
}

.radio-item.active {
	box-shadow: 0 0 0 2rpx #d502ff;
	transform: translateY(-4rpx);
}

.radio-cover {
	width: 100%;
	height: 120rpx;
}

.radio-name {
	font-size: 24rpx;
	font-weight: bold;
	margin: 10rpx 10rpx 5rpx;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
	color: #FFFFFF;
}

.radio-style {
	font-size: 20rpx;
	color: #B3B3B3;
	margin: 0 10rpx 10rpx;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.loading-indicator {
	justify-content: center;
	align-items: center;
	background-color: rgba(255, 255, 255, 0.05);
	animation: pulse 1.5s infinite;
}

.loading-spinner {
	width: 40rpx;
	height: 40rpx;
	border: 4rpx solid #d502ff;
	border-top-color: transparent;
	border-radius: 50%;
	animation: spin 1s linear infinite;
}

@keyframes spin {
	from {
		transform: rotate(0deg);
	}

	to {
		transform: rotate(360deg);
	}
}

@keyframes pulse {

	0%,
	100% {
		opacity: 1;
	}

	50% {
		opacity: 0.5;
	}
}
</style>